﻿Imports UCBase
Imports System.Drawing
Imports System.Windows.Forms

Public Class TabMonB
    Implements I_LoadSave

    Implements I_EditMode

    Private BackPic As New BackgroundCreator
    Private Mover As New Mover
    Private M_Edit As Boolean = True
    Private WithEvents ImageInput As I_ImageExchange
    Private PT As Integer
    Private AC As Integer = 0
    Private AV As Integer = 0
    Private FPS As Integer
    Private M_Resources As ResourceManager
    Private Pic As New PictureBox
    Private M_Font As New Font(System.Drawing.FontFamily.GenericSansSerif, 1, FontStyle.Bold, GraphicsUnit.Millimeter)
    Private OSD As Boolean = True
    Private M_Name As String = "TabMonitor"

    Public WriteOnly Property Resources() As ResourceManager
        Set(ByVal value As ResourceManager)
            M_Resources = value
        End Set
    End Property
    Public Sub CreateTab()
        Dim X As New TabPage(M_Name)
        X.BorderStyle = BorderStyle.Fixed3D
        X.ImageIndex = 1
        M_Resources.MainTab.TabPages.Insert(M_Resources.MainTab.TabPages.Count - 1, X)
        Pic.Dock = DockStyle.Fill
        Pic.Visible = True
        Pic.BackColor = Color.Black
        Pic.SizeMode = PictureBoxSizeMode.Zoom
        X.Controls.Add(Pic)
    End Sub
    Public Function GetSettings() As String Implements UCBase.I_LoadSave.GetSettings
        Return ""
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings

    End Sub

    Public Sub SetEditMode(ByVal Mode As UCBase.Diagram.EditMode) Implements UCBase.I_EditMode.SetEditMode
        If Mode = Diagram.EditMode.Locked Then
            Label1.Left = 10
            Label1.Top = 10
            TextBox1.Top = -100
            TextBox1.Left = -100
        Else
            Label1.Left = -100
            Label1.Top = -100
            TextBox1.Top = 10
            TextBox1.Left = 10
        End If
    End Sub

    Private Sub Socket2_Connect() Handles Socket2.Connect
        If Socket2.SocketType = Socket.Socket_Type.Image Then
            Dim S As Socket = Socket2.Remote
            ImageInput = S.Parent
        End If
    End Sub

    Private Sub ImageInput_ImageReady(ByVal Image As System.Drawing.Bitmap) Handles ImageInput.ImageOut1
        Dim BMP As New Bitmap(Image)
        Dim G As Graphics = Graphics.FromImage(BMP)
        G.Clear(Color.Black)
        G.DrawImage(Image, 0, 0)
        Dim S As String = "Source : " & Image.Width.ToString & " X " & Image.Height.ToString
        Dim B As New SolidBrush(Label3.BackColor)
        If OSD = True Then G.DrawString(S, M_Font, B, 5, 5)
        Pic.Image = BMP
    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.BackgroundImage = BackPic.CreatePic(Me.Width, Me.Height, Color.Silver)
        Mover.Connect(Me)
        Label1.Text = Me.Name
        Label1.BackColor = BackPic.FaceColor

    End Sub
    Private Sub TabMonitor_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Width = 155
        Me.Height = 190
    End Sub

    Private Sub Button3D5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D5.Click
        If OSD = True Then
            OSD = False
            EnableLed.State = Led.LedState.Led_Off
        Else
            OSD = True
            EnableLed.State = Led.LedState.Led_On
        End If
    End Sub

    Private Sub KnobControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KnobControl1.Load

    End Sub

    Private Sub KnobControl1_ValueChanged(ByVal Sender As Object) Handles KnobControl1.ValueChanged
        If KnobControl1.Value > 0 Then
            M_Font = New Font(System.Drawing.FontFamily.GenericSansSerif, KnobControl1.Value, FontStyle.Bold, GraphicsUnit.Millimeter)
        End If

    End Sub

    Private Sub Button3D1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D1.Click
        ColorDialog1.Color = Color.White
        If ColorDialog1.ShowDialog = DialogResult.OK Then
            Label3.BackColor = ColorDialog1.Color
        End If
    End Sub
End Class
